// set.hpp
// Set, a collection of items.
//
// Copyright (C) 2008  Maksim Sipos <msipos@mailc.net>
//
// This file is a part of the Ripe language project.
//
// Ripe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef R_SET_HPP
#define R_SET_HPP

#include "standard.hpp"
#include "adts/map.hpp"
#include "adts/iterator.hpp"

namespace Ripe {

  template <class T>
  class SetIterator;

  template <class T>
  class Set {
    public:
      // Check if element is in the set. Return true/false. If true, return
      // the value kept in set in *out.
      bool get(T element, T* out);

      // Like get() above, but throws an exception if the element isn't in
      // the set.
      T get(T element) throw(ErrorKey);

      // Check if element is in the set.
      bool has(T element);

      // Add an element to the set. Return true if the element was already in
      // the set.
      bool set(T element);

    private:
      friend class SetIterator<T>;
      
      Map<T,T> map;
  };
  
  template <class T>
  class SetIterator : public OneIterator<T> {
    public:
      SetIterator(Set<T>* s);
      
      bool has_more();
      
      T get();
    private:      
      MapIterator<T, T> iter;
  };
}

#include "set.cpp"

#endif // R_SET_HPP
